#!/usr/bin/python
# -*- coding: UTF-8 -*-
# author : bird.zhang@ximalaya.com

import pandas as pd

import numpy as np
import matplotlib.pyplot as plt
import matplotlib

matplotlib.rcParams['font.sans-serif'] = [u'SimHei']
matplotlib.rcParams['axes.unicode_minus'] = False

df = pd.read_csv('tb_liveroom_metadata.csv', index_col='id')

# df.info()

df = df[['uid', 'room_id', 'metadata_id', 'metadata_value']]

grouped = df.groupby('metadata_value')['metadata_value'].count()

# print(type(df.groupby('metadata_id').count()))

print(grouped)

grouped.plot(kind='barh')

# print(grouped.columns)
# grouped = df.DataFrame(grouped)

# y轴数据
# people = ('James', 'Durant', 'Kobe', 'Wade', 'Curry', 'Magic', 'Hardan')
metadata_name = grouped.index
y_pos = np.arange(len(metadata_name))

# x轴数据
# performance = 30 + 70 * np.random.rand(len(metadata_name))  # 随机产生len(people)个 [0,1）的数
count = grouped.values  # 随机产生len(people)个 [0,1）的数
# 误差
error = np.random.rand(len(metadata_name))
# 这里是产生横向柱状图 barh h--horizontal
# plt.barh(y_pos, performance, xerr=error, align='center', alpha=0.4)

plt.barh(y_pos, count, align='center', alpha=0.4)
plt.yticks(y_pos, metadata_name)
# x轴含义
plt.xlabel('count')
# x轴范围
plt.xlim(0, 500)
# 图片标签
plt.title('anchor_metadata')
# plt.show()
